<?php
/*
 * 手机客户端 我赞过的作品列表
 * 传入参数 
 * 2013-12-24
 */
include "inc/public_header.php";
include "inc/MiniaturePro.class.php";
include "func/user.php";				//用户信息处理函数
include "func/pic.php";					//图片处理函数

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
if(!$uInfoArr){
	echo json_encode(array("success"=>"0","errCode"=>"0"));
	die;
}
$uid = $uInfoArr["uid"]; //用户信息主键


$reJson = array();//构建返回值
 
$page			= $_REQUEST["page"]; 			//页数，第一页为0
$pagesize		= $_REQUEST["pagesize"];		//每页记录数
$panelWidth		= $_REQUEST["panelWidth"];		//屏幕宽度
$hd_id			= $_REQUEST["hd_id"];			//活动主键

if($panelWidth<480){
	$imgWidth  = 100;
}else if($panelWidth>=480 && $panelWidth<=600){
	$imgWidth = 200;
}else {
	$imgWidth = 300;
}
	 
if(!isset($page)){
	$page = 0;
}
if(!isset($pagesize)){
	$pagesize = 200; //默认每页200条
}

$reJson["success"] = "1";


//获取作品总数量
$sql ="select count(0) as ct
		from 
				new_weituo_zuopin a	
				inner join new_weituo_pingfen b on a.id=b.zpid
				left join new_weituo_person d on a.uid=d.uid
		where
				a.dr='0'
				and a.aflag='1'
				and b.uid='".$uid."'
		";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and a.hd_id='".$hd_id."' ";
}
$db->query($sql);
$db->next_record();
$reJson["count"] = $db->f("ct"); //设置作品总数量（不分页）

//作品信息列表
$sql ="select 
				a.id
				,a.uid
				,a.aname
				,a.gz_count
				,a.ll_count
				,a.pl_count
				,a.czln
				,a.img_path
				,a.img_id
				,a.type_id
				,a.zan_count
				,e.id as mini_img_id
				,e.awidth as mini_img_width
				,e.aheight as mini_img_height
				,e.aname as mini_img_aname
		from 
				new_weituo_zuopin a	
				left join new_weituo_person d on a.uid=d.uid
				inner join new_weituo_pingfen b on a.id=b.zpid
				left join new_weituo_pic_size e on a.img_id=e.img_id and e.awidth='".$imgWidth."'
		where
				a.dr='0'
				and a.aflag='1'
				and b.uid='".$uid."'
		";
if(isset($hd_id) && $hd_id!=""){
	$sql = $sql." and a.hd_id='".$hd_id."' ";
}
$sql = $sql."GROUP BY id limit ".($page * $pagesize).",".$pagesize;

$db->query($sql);
$worksArr = array();
$miniature = new MiniaturePro();	//构建缩略图处理类
$count = 0;
while($db->next_record()){
	//处理生成缩略图
	$imgInfos = pic_resize(
							 $miniature
							,$db->f("img_path")
							,$db->f("mini_img_aname")
							,$imgWidth
							,$db->f("img_id")
							,$db->f("mini_img_id")
							,$db->f("mini_img_width")
							,$db->f("mini_img_height"));
	if($imgInfos["success"]=="0"){
		//图片有问题，无法显示
		continue;
	}
	$count++;
	$worksArr[] = array(
		"title"=>$db->f("aname")							//作品标题
		,"worksid"=>$db->f("id")							//作品id
		,"imgurl"=>$imgInfos["mini_img_url"]				//图片
		,"authorid"=>$db->f("uid")							//作者id
		,"praise"=>$db->f("zan_count")						//赞
		,"imgWidth"=>(string)$imgInfos["mini_img_width"]	//图片宽度
		,"imgHeight"=>(string)$imgInfos["mini_img_height"]	//图片高度
	);
}	
$reJson["count"] = $count;
$reJson["list"]=$worksArr;
echo json_encode($reJson);
?>